#include <iostream>
#include <string>
#include <cstdlib>
#include "mainDriver.h"
#include "miscFunction.h"
#include "DB.h"

using namespace std;

int main()
{
    mainDriver mainP;
    
    bool member = true;
    string loginType;
    bool correctOption = false;
    string userKeyStr;
    char* userKey = new char;
    
    drawLine('=',35);
    cout << "Welcome to the Hotel Review System" << endl;
    drawLine('=',35);
    
    cout << endl << "Choose One of the following Login Type:" << endl;
    cout << "a) Member" << endl;
    cout << "b) Admin" << endl << endl;
    
    while(!correctOption)
    {
        cout << "Your Option : ";
        getline(cin,userKeyStr);
        
        if(userKeyStr.length() < 0 || userKeyStr.length() > 1)
            cout << "Error: Invalid Option Length! Re-Enter ";
        else if(!(userKeyStr[0] >= 'a' && userKeyStr[0] <= 'b'))
        {
            cout << "Error : Invalid Option! Re-enter " << endl << endl;
        }
        else
            correctOption = true;
    }
    
    if(userKeyStr == "a")
    {
        void* userAccAll;
        
        cout << endl << "Login to Proceed" << endl;
        drawLine('-',17);
        cout << endl;
        
        userAccAll = mainP.login("Member");
        
        MemberAccount userAcc (userAccAll);
        
        cout << endl;

        userKey[0] = ' ';
        
        drawLine('#',(userAcc.getMemberName().length() + 9));
        cout << "Welcome " << userAcc.getMemberName() << "!" << endl;
        drawLine('#',(userAcc.getMemberName().length() + 9));
        cout << endl;
        
        while(userKey[0] != 'f')
        {
            cout << "Choose one the Options Below: " << endl;
            cout << "a)Search Hotel (For its informations)" << endl;
            cout << "b)View Permitted Hotel that can make a Review" << endl;
            cout << "c)Create Hotel Review" << endl;
            cout << "d)View All Hotel Reviews" << endl;
            cout << "e)Request to Make a Review on a Hotel" << endl;
            cout << "f)Exit" << endl;
            
            cout << endl << "Your Option : " ;
            getline(cin, userKeyStr);
            strcpy(userKey,userKeyStr.c_str());
            cout << endl;
            
            if(userKeyStr.length() > 1)
                cout << "Error: Detected a Sentence. Retry!" << endl << endl;
            else if((userKey[0] = tolower(userKey[0])) && (!(userKey[0] >= 'a' && userKey[0] <= 'f')))
            {
                cout << "Error : Invalid Option!. Retry!" << endl << endl;
            }
            else
            {
                switch(userKey[0])
                {
                    case 'a' :
                                userAcc.searchHotel();
                        break;
                        
                    case 'b' :
                                userAcc.viewPermitedHotel();
                        break;
                        
                    case 'c' :
                                userAcc.createHotelReview();  
                        break;
                        
                    case 'd' :
                                userAcc.viewHotelReview();
                        break;
                        
                    case 'e' : 
                                userAcc.requestReviewPermission();                     
                        break;
                        
                    case 'f' :
                                drawLine('=',50);
                                cout << "Exiting Hotel Review System... " << endl;
                                drawLine('=',50);
                        break;
                }
            }
        }
        
        mainP.logout();
    }
    else
    {
        void* userAccAll;
        
        cout << endl << "Login to Proceed" << endl;
        drawLine('-',17);
        cout << endl;
        
        userAccAll = mainP.login("Admin");
        
        AdminAccount userAcc (userAccAll);
        
        cout << endl;
        userKey[0] = ' ';
        
        drawLine('#',(userAcc.getMemberName().length() + 9));
        cout << "Welcome " << userAcc.getMemberName() << "! (Admin)" << endl;
        drawLine('#',(userAcc.getMemberName().length() + 9));
        cout << endl;
        
        while(userKey[0] != 'm')
        {
            cout << "Choose one the Options Below: " << endl;
            cout << "a)Search Hotel (For its informations)" << endl;
            cout << "b)Create Hotel Review" << endl;
            cout << "c)View All Hotel Reviews" << endl;
            cout << "d)Create Member" <<endl;
            cout << "e)Delete Member" <<endl;
            cout << "f)Modify Member" <<endl;
            cout << "g)Delete Hotel Review" <<endl;
            cout << "h)Allow Request Review" <<endl;
            cout << "i)View Review Summaries" <<endl;
            cout << "j)Create Hotel Item" <<endl;
            cout << "k)Delete Hotel Item" <<endl;
            cout << "l)Modify Hotel Item" <<endl;						
            cout << "m)Exit" << endl;
            
            cout << endl << "Your Option : " ;
            getline(cin, userKeyStr);
            strcpy(userKey,userKeyStr.c_str());
            cout << endl;
            
            if(userKeyStr.length() > 1)
                cout << "Error: Detected a Sentence. Retry!" << endl << endl;
            else if((userKey[0] = tolower(userKey[0])) && (!(userKey[0] >= 'a' && userKey[0] <= 'm')))
            {
                cout << "Error : Invalid Option!. Retry!" << endl << endl;
            }
            else
            {
                switch(userKey[0])
                {
                    case 'a' :
                    {
                        userAcc.searchHotel();
                        break;
                    }
                        
                    case 'b' :
                    {
                        userAcc.createHotelReview();
                        break;
                    }
                        
                    case 'c' :
                    {
                        userAcc.viewHotelReview();
                        break;
                    }
                        
                    case 'd' :
                    {
                        userAcc.createMemberAccount();
                        break;
                    }
                        
                    case 'e':
                    {
                        userAcc.deleteMemberAccount();
                        break;
                    }
                        
                    case 'f':
                    {
                        userAcc.modifyMemberAccount();
                        break;
                    }
                        
                    case 'g':
                    {
                        userAcc.deleteHotelReview();
                        break;
                    }
                        
                    case 'h':
                    {
                        userAcc.allowHotelReview();
                        break;
                    }
										
                    case 'i':
                    {
                        userAcc.viewSummary();
                        break;
                    }

                    case 'j' :
                    {
                        HotelItem hotelItem;
                        hotelItem.addHotelItem();
                        break;
                    }
                        
                    case 'k':
                    {
                        HotelItem hotelItem;
                        hotelItem.deleteHotelItem();
                        break;
                    }
                        
                    case 'l':
                    {
                        HotelItem hotelItem;
                        hotelItem.modifyHotelItem();
                        break;
                    }										
                    case 'm' :
                    {
                        drawLine('=',50);
                        cout << "Exiting Hotel Review System... " << endl;
                        drawLine('=',50);
                        break;
                    }
                }
            }
        }
        
        mainP.logout();
    }
}

